import 'package:series_play/net/http_manager.dart';
import 'package:series_play/net/http_response.dart';

import '../../bean/drama_info_result_data.dart';
import '../../bean/drama_simple_data.dart';

class DramaApi {
  static DramaApi instance = DramaApi._();

  factory DramaApi() => instance;

  DramaApi._();

  /// 推荐列表
  Future<HttpResponse<List<DramaSimpleData>>> recommendList(
    int pageNum,
    int pageSize,
  ) async {
    return await HttpManager.instance.post(
      '/drama/recommend',
      data: {'pageNum': pageNum, 'pageSize': pageSize},
      fromJsonList: (json) {
        return (json).map((e) => DramaSimpleData.fromJson(e)).toList();
      },
    );
  }

  /// 新剧列表
  Future<HttpResponse<List<DramaSimpleData>>> newDramaList(
    int pageNum,
    int pageSize,
  ) async {
    return await HttpManager.instance.post(
      '/drama/new',
      data: {'pageNum': pageNum, 'pageSize': pageSize},
      fromJsonList: (json) {
        return (json).map((e) => DramaSimpleData.fromJson(e)).toList();
      },
    );
  }

  /// 分类列表
  Future<HttpResponse<List<DramaSimpleData>>> categorizeList(
    String type,
    int pageNum,
    int pageSize,
  ) async {
    return await HttpManager.instance.post(
      '/drama/recently',
      data: {'type': type, 'pageNum': pageNum, 'pageSize': pageSize},
    );
  }

  /// 追剧列表
  Future<HttpResponse<List<DramaSimpleData>>> bingeWatchList(
    int pageNum,
    int pageSize,
  ) async {
    return await HttpManager.instance.post(
      '/drama/zhuju',
      data: {'pageNum': pageNum, 'pageSize': pageSize},
      fromJsonList: (json) {
        return (json).map((e) => DramaSimpleData.fromJson(e)).toList();
      },
    );
  }

  /// 播放历史
  Future<HttpResponse<List<DramaSimpleData>>> watchHistoryList(
    int pageNum,
    int pageSize,
  ) async {
    return await HttpManager.instance.post(
      '/drama/recently',
      data: {'pageNum': pageNum, 'pageSize': pageSize},
      fromJsonList: (json) {
        return (json).map((e) => DramaSimpleData.fromJson(e)).toList();
      },
    );
  }

  /// 剧详情
  Future<HttpResponse<DramaInfoResultData>> dramaInfo(int diId) async {
    return await HttpManager.instance.post(
      '/drama/info',
      data: {'diId': diId},
      fromJson: DramaInfoResultData.fromJson,
    );
  }

  /// 新剧列表
  Future<HttpResponse<List<DramaSimpleData>>> dramaLoveStatueChange(
    String diId, {
    bool isLove = true,
  }) async {
    return await HttpManager.instance.post(
      '/drama/zan',
      data: {'diId': diId, 'zhui': isLove},
    );
  }

  Future<HttpResponse<List<DramaSimpleData>>> dramaSearch(
    String key,
    int pageNum,
    int pageSize,
  ) async {
    return await HttpManager.instance.post(
      '/drama/search',
      data: {'key': key, 'pageNum': pageNum, 'pageSize': pageSize},
    );
  }
}
